package com.sunq.studio.sys.controller;

import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by sunq on 2019/7/9.
 */

@RestController
@RequestMapping("/api")
public class ApiController {

    //wxf5d800e37a8ffe04；
    // cee6aa7b647174cdb1e65a8c25daa4df


    @GetMapping("/uptoken")
    public Map uptoken(){

        String accessKey = "umLMyeoflFmkuoDqZMQ_TkWU6wuJn_ME65OyzF-Y";
        String secretKey = "a6A4uXjfC21t2tQ3Ilj7brDvd_6kEmzn1q1Avqd4";

        String bucket = "sunq";

        Auth auth = Auth.create(accessKey, secretKey);
        StringMap putPolicy = new StringMap();
        putPolicy.put("returnBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"fsize\":$(fsize)}");
        long expireSeconds = 3600;
        String upToken = auth.uploadToken(bucket, null, expireSeconds, putPolicy);
        Map<String,String > res=new HashMap<String,String>();
        res.put("uptoken",upToken);
        return  res;
    }



}
